package com.itheima.config;

import com.itheima.interceptor.HelloInterceptor;
import com.itheima.interceptor.TokenInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器Interceptor
 *
 * @author GY
 * @version V1.0
 * @date 2025-01-17 9:44
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final HelloInterceptor helloInterceptor;
    private final TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*registry.addInterceptor(helloInterceptor)
                .addPathPatterns("/**");
        */

        registry.addInterceptor(tokenInterceptor)
                //   /** : 拦截所有Handler【controller中标记了@RequestMapping的方法】
                .addPathPatterns("/**")
                // 指定不拦截的URL
                .excludePathPatterns("/login");
    }
}
